<template>
	<view class="detailedness">
		<header :style="'padding-top: '+height.top+'px;height: '+(44+height.top)+'px;'">
			<view :style="'height: '+height.height+'px;top: '+height.top+';'">
				<u-icon @click="retreat(1)" name="arrow-left" color="#272635" size="32"></u-icon>
				<span>详情</span>
			</view>
		</header>
		<swiper circular :autoplay="true" class="x-swiper">
			<swiper-item v-for="val in data.banner" :key="val">
				<image mode="aspectFill" :src="URLimg+val"></image>
			</swiper-item>
		</swiper>
		<main>
			<p class="introduce">
				{{data.name}}
			</p>
			<view class="price">
				<p>
					<span>
						<text v-if="type==1">￥</text>
						{{type==1?data.sell_price:data.integral}}
						<text v-if="type==2">积分</text>
					</span>
					<i>￥{{type==1?data.market_price:data.original}}</i>
				</p>
				<span>库存：{{data.stock}}</span>
			</view>
			<p class="expressage">
				快递费：￥{{data.freight}}
				<button open-type="share" plain>
					<image src="../../../static/home/24.png" mode="widthFix"></image>
				</button>
			</p>
			<view class="evaluateDom" @click="spik('pages/homeList/comment/comment?id='+data.id+'&type='+type)">
				评价({{data.evaluate}})
				<span>查看全部
					<u-icon name="arrow-right" color="#9E9E9E" size="23"></u-icon>
				</span>
			</view>
			<p class="inDetail">商品详情</p>
			<view class="LabeledEdit">
				<u-parse :content="data.detail"></u-parse>
			</view>
		</main>
		<footer>
			<view class="collect">
				<span v-if="type==1" @click="collect">
					<image v-if="data.collection!=1" mode="widthFix" src="../../../static/home/6.png"></image>
					<image v-if="data.collection==1" mode="widthFix" src="../../../static/home/7.png"></image>
					收藏
				</span>
				<p v-if="type==2">{{data.integral}}<text>积分</text></p>
			</view>
			<view class="function">
				<span v-if="type==2" @click="spik('pages/homeList/integral/integral')">立即兑换</span>
				<!-- <span @click="apifun.showModal('预约','是否确定预约该产品？',appointmentOrder)" class="grey"
					v-if="type==1&&data.appointment!=1">预定</span> -->
				<span @click="apifun.showModal('购物车','是否确定添加该商品到购物车？',getShoppingCart)" class="grey"
					v-if="type==1">加入购物车</span>
				<span v-if="type==1" @click="spik('pages/homeList/payment/payment')">立即购买</span>
			</view>
		</footer>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				judge:true,
				id: '',
				type: 1,
				html: '',
				height: {},
				data: {},
				urls: '',
				URLimg: this.URLimg,
				apifun: this.apifun,
			};
		},
		onShareAppMessage: function(res) {
			return {
				title: this.data.name,
				path: '/pages/homeList/detailedness/detailedness?id=' + this.id + '&type=' + this.type,
				imageUrl: this.URLimg + this.data.image
			}
		},
		onLoad(res) {
			this.id = res.id
			this.type = res.type
			this.urls = this.type == 1 ? '/api/goods/getGoodsdetails' : '/api/goods/getPointsMallDetails'
			this.getGoodsdetails()
			this.height = uni.getStorageSync('header')
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})
		},
		onShow() {
			let res = uni.getEnterOptionsSync()
			if (res.scene == 1007 || res.scene == 1008 || res.scene == 1017 || res.scene == 1044 || res.scene == 1154 || res.scene == 1155) {
				this.judge=false
			}
		},
		methods: {
			retreat(delta) {
				if(this.judge){
					uni.navigateBack({
						delta,
					});
				}else{
					uni.switchTab({
						url: '/pages/tabbar/index'
					});
				}
			},
			spik(url) {
				if (this.type == 1) {
					uni.setStorageSync('commodity', this.data)
				} else {
					uni.setStorageSync('integral', this.data)
				}
				uni.navigateTo({
					url: '/' + url
				});
			},
			getGoodsdetails() {
				this.apifun.unirequest(this.urls, 'post', {
					id: this.id
				}, (res) => {
					this.data = res.data
				}, true)
			},
			collect() {
				this.apifun.unirequest('/api/goods/collect', 'post', {
					goods_id: this.data.id
				}, (res) => {
					if (res.code == 0) {
						return this.apifun.toast(res.msg)
					}
					this.getGoodsdetails()
				})
			},
			appointmentOrder() {
				this.apifun.unirequest('/api/order/appointmentOrder', 'post', {
					goods_id: this.data.id
				}, (res) => {
					if (res.code == 0) {
						return this.apifun.toast(res.msg)
					}
					this.apifun.toast('预约成功')
					this.getGoodsdetails()
				})
			},
			getShoppingCart() {
				this.apifun.unirequest('/api/order/getShoppingCart', 'post', {
					goods_id: this.data.id
				}, (res) => {
					if (res.code == 0) {
						return this.apifun.toast(res.msg)
					}
					this.apifun.toast('添加成功')
					this.getGoodsdetails()
				})
			}
		}
	}
</script>

<style lang="scss">
	.detailedness {
		padding-bottom: 140rpx;

		&>footer {
			width: 100%;
			height: 100rpx;
			background-color: #fff;
			position: fixed;
			bottom: 0;
			left: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 30rpx 0 44rpx;
			box-sizing: border-box;

			&>.function {
				display: flex;

				&>span {
					width: 190rpx;
					height: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #9E190F;
					color: #fff;
					font-size: 14px;
					border-radius: 35rpx;
					margin-left: 10rpx;
				}

				&>.grey {
					background-color: #E5E5E5 !important;
					color: #9E9E9E !important;
				}
			}

			&>.collect {
				&>p {
					font-size: 50rpx;
					font-weight: bold;
					color: #F1221B;

					&>text {
						color: #666666;
						font-size: 14px;
						font-weight: 400;
					}
				}

				&>span {
					display: flex;
					flex-direction: column;
					align-items: center;
					font-size: 12px;
					color: #9E9E9E;

					&>image {
						width: 40rpx;
						margin-bottom: 11rpx;
						@include cssimg;
					}
				}
			}
		}

		&>main {
			background-color: #f4f4f4;
			width: 100%;
			transform: translateY(-20rpx);
			border-radius: 20rpx 20rpx 0 0;
			z-index: 101;
			padding-top: 20rpx;

			&>.LabeledEdit {
				width: 690rpx;
				margin: 0 auto;
			}

			&>.inDetail {
				width: 690rpx;
				font-size: 28rpx;
				font-weight: bold;
				margin: 30rpx auto 20rpx;
			}

			&>.evaluateDom {
				width: 690rpx;
				height: 100rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 20rpx 0 28rpx;
				box-sizing: border-box;
				background-color: #fff;
				border-radius: 20rpx;
				margin: 0 auto;
				font-size: 28rpx;
				font-weight: bold;

				&>span {
					color: #9E9E9E;
					display: flex;
					font-size: 26rpx;
					align-items: center;

					&>.u-icon {
						margin-left: 10rpx;
					}
				}
			}

			&>.expressage {
				width: 690rpx;
				margin: 26rpx auto 42rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 13px;
				color: #9E9E9E;

				&>button {
					border: 0px;

					&>image {
						width: 40rpx;
						@include cssimg;
					}
				}
			}

			&>.price {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 690rpx;
				margin: 0 auto;

				&>p {
					display: flex;
					align-items: center;

					&>span {
						color: #D31E11;
						font-size: 18px;
						font-weight: bold;

						&>text {
							font-size: 12px;
						}
					}

					&>i {
						font-size: 24rpx;
						color: #999999;
						margin-left: 20rpx;
						text-decoration: line-through;
					}
				}

				&>span {
					font-size: 26rpx;
					color: #9E9E9E;
				}
			}

			&>.introduce {
				width: 690rpx;
				font-size: 36rpx;
				font-weight: bold;
				margin: 10rpx auto 30rpx;
			}
		}

		&>.x-swiper {
			width: 750rpx;
			height: 750rpx;
			margin: 0rpx auto;
			overflow: hidden;
			z-index: 100;

			image {
				width: 750rpx;
				height: 750rpx;
				display: block;
				@include cssimg;
			}
		}

		&>header {
			width: 750rpx;
			margin: 0 auto;
			position: fixed;
			top: 0;
			z-index: 999;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			flex-direction: column;

			&>view {
				width: 690rpx;
				z-index: 999;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);

				&>span {
					position: absolute;
					left: 50%;
					top: 50%;
					transform: translate(-50%, -50%);
					font-size: 18px;
					font-weight: bold;
				}

				&>.u-icon {
					position: absolute;
					left: 0;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
	}
</style>